/**
 * 工具类-格式化参数
 * @param {*} data
 * @returns
 */
export function formatQuery(data) {
  return (
    '?' +
    Object.keys(data)
      .map((key) => {
        return `${key}=${typeof data[key] == 'string' ? encodeURIComponent(data[key]) : data[key]}`
      })
      .join('&')
  )
}

/** 将get参数转对象 */
export function getQuery() {
  const params = {}
  const queryString = window.location.search.substring(1)
  const pairs = queryString.split('&')

  for (let i = 0; i < pairs.length; i++) {
    const pair = pairs[i].split('=')
    params[pair[0]] = decodeURIComponent(pair[1] || '')
  }
  return params
}
